home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PROG_TOO / C027B.ZIP / JAS / JAS.H < prev    next >
Text File  |  1990-03-30  |  3KB  |  163 lines

  1.  
  2. /*
  3.  * Copyright (c) 1988 by Sozobon, Limited.  Author: Joseph M Treat
  4.  *
  5.  * Permission is granted to anyone to use this software for any purpose
  6.  * on any computer system, and to redistribute it freely, with the
  7.  * following restrictions:
  8.  * 1) No charge may be made other than reasonable charges for reproduction.
  9.  * 2) Modified versions must be clearly marked as such.
  10.  * 3) The authors are not responsible for any harmful consequences
  11.  *    of using this software, even if they result from defects in it.
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <ctype.h>
  16.  
  17. #include <setjmp.h>
  18.  
  19. #define short int
  20.  
  21. typedef struct _sym {
  22.     struct _sym *next;
  23.     char *name;
  24.     long value;
  25.     unsigned short index;
  26.     unsigned short flags;
  27.     unsigned short access;
  28. } SYM;
  29.  
  30. typedef struct {
  31.     struct _sym *psym;
  32.     long value;
  33. } EXPR;
  34.  
  35. /*
  36.  * Flags for symbols
  37.  */
  38. #define UNK    0x0000
  39. #define BSS    0x0100
  40. #define TXT    0x0200
  41. #define DAT    0x0400
  42. #define SEGMT    0x0700
  43. #define EXTERN    0x0800
  44. #define GLOBAL    0x2000
  45. #define EQUATED    0x4000
  46. #define DEFINED    0x8000
  47.  
  48. typedef struct {
  49.     unsigned short mode;
  50.     unsigned char reg, inx;
  51.     EXPR expr;
  52. } OPERAND;
  53.  
  54. typedef struct {
  55.     char mnemon[8];
  56.     unsigned short op0, op1;
  57.     char size;
  58.     char format[14];
  59.     unsigned char flags;
  60. } INST;
  61.  
  62. typedef struct {
  63.     INST *inst;
  64.     OPERAND *op0, *op1;
  65.     short misc;
  66. } STMT;
  67.  
  68. /*
  69.  * Flags for operand types
  70.  */
  71. #define O_NONE    0x0000
  72. #define O_AN    0x0001
  73. #define O_DN    0x0002
  74. #define    O_INDR    0x0004
  75. #define O_DISP    0x0008
  76. #define O_POST    0x0010
  77. #define O_PRE    0x0020
  78. #define O_INDX    0x0040
  79. #define O_ABS    0x0080
  80. #define    O_PCRL    0x0100
  81. #define O_PCIX    0x0200
  82. #define O_IMM    0x0400
  83. #define O_USP    0x0800
  84. #define O_CCR    0x1000
  85. #define O_SR    0x2000
  86. #define O_REGS    0x4003
  87. #define O_ALL    0x07ff
  88. #define O_DMEM    0x00fc
  89. #define O_DST    0x00fe
  90. #define O_MEM    0x03fc
  91. #define O_LAB    0x0380
  92. #define O_STAT    0x03cc
  93. #define O_WRT    0x00ec
  94. #define O_RD    0x03dc
  95. #define O_NAN    0x07fe
  96.  
  97. /*
  98.  * Flags for the size field
  99.  */
  100. #define S_B    0x01
  101. #define S_W    0x02
  102. #define S_L    0x04
  103. #define S_BW    S_B|S_W
  104. #define S_BL    S_B|S_L
  105. #define S_WL    S_W|S_L
  106. #define S_BWL    S_B|S_W|S_L
  107.  
  108. /*
  109.  * Flags for special actions and defaults
  110.  */
  111. #define F_B    0x01
  112. #define F_W    0x02
  113. #define F_L    0x04
  114. #define F_TXT    0x08
  115. #define F_Q    0x10
  116. #define F_TV    0x20
  117. #define F_MQ    0x40
  118. #define F_PC    0x80
  119.  
  120. typedef struct _list {
  121.     struct _list *next;
  122.     union {
  123.         SYM *sym;
  124.         EXPR val;
  125.     } u;
  126. } LIST;
  127.  
  128. /*
  129.  * Types of things that get generated
  130.  */
  131. #define GENSTMT  1
  132. #define GENVALUE 2
  133. #define GENRELOC 3
  134. #define GENPCREL 4
  135. #define GENBRNCH 5
  136.  
  137. #define CBLEN 512
  138.  
  139. typedef struct {
  140.     unsigned char nbits;
  141.     unsigned char action;
  142.     int line;
  143.     EXPR value;
  144. } CBUF;
  145.  
  146. typedef struct _clist {
  147.     struct _clist *next;
  148.     short cnt, inx;
  149.     CBUF cblock[CBLEN];
  150. } CLIST;
  151.  
  152. typedef struct _branch BRANCH;
  153. struct _branch {
  154.     long where;
  155.     CBUF *cptr;
  156.     BRANCH *link;
  157. };
  158.  
  159. #define ALLOC(n,t) ((t *) allocate( (unsigned) ( (n) * sizeof (t) ) ))
  160. #define ALLO(t)    ALLOC(1,t)
  161. #define STRCPY(s) strcpy( ALLOC(1+strlen(s),char), s )
  162. extern char *allocate(), *strcpy();
  163.